package com.ait.edu.service.impl;

import com.ait.edu.entity.Course;
import com.ait.edu.entity.Teacher;
import com.ait.edu.mapper.TeacherMapper;
import com.ait.edu.service.CourseService;
import com.ait.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-06-06
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    private CourseService courseService;

    /* h获取讲师 */
    @Override
    public Map<String, Object> getpage(Page<Teacher> page) {


        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");

        IPage<Teacher> page1 = this.page(page, wrapper);

        HashMap<String, Object> map = new HashMap<>();

        List<Teacher> records = page.getRecords();
        long total = page.getTotal();
        long current = page.getCurrent();
        long size = page.getSize();
        long pages = page.getPages();

        boolean hasNext = page.hasNext();
        boolean hasPrevious = page.hasPrevious();


        map.put("items",records);
        map.put("total",total);
        map.put("current",current);
        map.put("size",size);
        map.put("pages",pages);

        map.put("hasNext",hasNext);
        map.put("hasPrevious",hasPrevious);
        return map;
    }


    /*
    * 显示页面讲师详情，课程
    *
    * return map
    *
    * */
    @Override
    public Map<String, Object> getCourseTeacher(String id) {
        HashMap<String, Object> map = new HashMap<>();
        Teacher byId = this.getById(id);
        map.put("teacher",byId);

        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);

        List<Course> list = courseService.list(wrapper);
        map.put("course",list);

        return map;
    }
}
